from django.db import models


class Reporter(models.Model):
    full_name = models.CharField(max_length=70)

    def __str__(self):
        return self.full_name


class Article(models.Model):
    pub_date = models.DateField()
    headline = models.CharField(max_length=200)
    content = models.TextField()
    reporter = models.ForeignKey(Reporter, on_delete=models.CASCADE)

    def __str__(self):
        return self.headline


# 分类表
class Class(models.Model):
    id = models.IntegerField(auto_created=True)
    class_name = models.CharField(max_length=20, verbose_name='职位类别')
    # null=True允许在数据库中存储NULL值, blank=True并且在表单中允许为空
    # related_name='children' 设置反向关联的名称，可以通过parent.children访问所有子类别
    parent = models.ForeignKey('self', on_delete=models.SET_NULL, null=True, blank=True, related_name='children')

    def __str__(self):
        return self.class_name

    class Meta:
        table_name = "Class"


# 职位表
class Job(models.Model):
    STATUS = (
        (0, '行政类'),
        (1, '管理类'),
        (2, '专业类'),
        (3, '营销类'),
    )
    id = models.IntegerField(auto_created=True)
    c_id = models.IntegerField(verbose_name='类别id')
    department = models.ForeignKey(Class, on_delete=models.SET_NULL, null=True, related_name='department')
    created_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
    update_time = models.DateTimeField(auto_now=True, verbose_name='更新时间')

    class Meta:
        table_name = "Job"
